<script>
   $(document).ready(function () {
     table_main("#revision_table");
   });
</script>

<div class="card" id="table-card">
  <div class="bg-light navbar navbar-expand">
      <ul class="nav navbar-expand navbar-nav-scroll">
        <li class="nav-item">
          <a class="btn nav-link text-secondary" data-toggle="tooltip" data-placement="top" title="Selected per page"> Selected <span id="select-count" class="badge badge-dark">0</span></a>
        </li>
      </ul>
  </div>
  <div class="card-body" style="overflow-x:hidden;">
    <% unless @revisions.empty? %>
      <div class="my-0 text-secondary small "><%= page_entries_info(@revisions) %>s</div>
    <% end %>
    <table  id="revision_table" class="nowrap table table-hover" sstyle="width:100%; text-align:left">
      <thead style="text-align:left;">
        <tr>
          <th><input type="checkbox"  id="selectall" /></th>
          <th><%=translation('users.profile.title')%></th>
          <th>Author</th>
          <th>Updated at</th>
          <th>Action</th>                                
        </tr>       
      </thead>
      <tbody> 
        <% @revisions.each do |revision| %>
          <tr id="n<%= revision.vid %>">
            <td><input  class="selectedId" value="<%= revision.vid %>" type="checkbox" /></td>
            <td>
            <% if revision.status == 1 %><i class="fa fa-check text-success"></i> <% elsif revision.status == 0 %><i class="fa fa-ban text-danger"></i> <% elsif revision.status == 4 %><i class="fa fa-circle text-priamry"></i> <% end %>
              <a class="text-dark font-weight-bold" data-toggle="modal" data-target="#ninfo<%= revision.vid %>" href="javascript:void(0);"> <%= revision.title.truncate(20) %></a><br />
            </td>
            <td>
              <a class="text-info" href="/profile/<%= revision.author&.name %>"><%= revision.author&.name %></a> 
            </td>
            <td>
              <span style="color:grey;"><%= time_ago_in_words(revision.updated_at) %> ago</span>
            </td>
            <td>
              <a class="badge badge-pill badge<% if revision.status == 0 %>-success<% else %>-secondary disabled<% end %> publish" data-remote="true" href="/moderate/revision/publish/<%= revision.vid %>"><i class="fa fa-check-circle fa-white"></i> Publish post</a>
                  <a class="badge badge-pill badge-danger ban a<%= revision.author.id %>" data-remote="true" <% if revision.author.status == 0 %>style="display:none;"<% end %> href="/ban/<%= revision.author.id %>">Ban</a>  
                  <a class="badge badge-pill badge-secondary unban a-unban<%= revision.author.id %>" data-remote="true"  <% if revision.author&.status == 1 %>style="display:none;"<% end %> href="/unban/<%= revision.author.id %>">Unban</a>
                <script>
                  $('#n<%= revision.vid %> .publish').bind('ajax:success', function(e){
                    $('#n<%= revision.vid %>').hide()
                    notyNotification('relax', 3000, 'success', 'topRight', 'Revision published');

                  });  
                  $('.a<%= revision.author.id %>.ban').bind('ajax:success', function(e){
                    $('.a<%= revision.author.id %>').hide()  // ban toggle
                    $('.a-unban<%= revision.author.id %>').show()
                    notyNotification('relax', 3000, 'danger', 'topRight', 'Author banned');

                  });
                  $('.a-unban<%= revision.author.id %>.unban').bind('ajax:success', function(e){
                    $('.a-unban<%= revision.author.id %>').hide()
                    $('.a<%= revision.author.id %>').show()
                    notyNotification('relax', 3000, 'success', 'topRight', 'Author unbanned');
                  });
                </script>
            </td>
          </tr>
            <div class="modal fade" id="ninfo<%= revision.vid %>">
              <div class="modal-dialog" >
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title"><a href="<% if !revision.parent.nil? %><%= revision.parent.path %><% end %>"><%= revision.title%></a></h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span>&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                    <%= revision.body %>
                  </div>
                </div>
              </div>
            </div>
        <% end %>
      </tbody>
    </table>                      
  </div>
</div>
<div class="page-table">
  <div class="float-right">
    <%= will_paginate @revisions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || @revisions.empty?%>
  </div>
  <div class="float-left text-secondary">
    Batch  <%= @revisions.current_page%> of <%= @revisions.total_pages %> total Pages
  </div>
</div>
